#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <set>
using namespace std;
class Solution
{
public:
    const int inf = 0x7fffffff;
    bool checkPossibility(vector<int> &nums)
    {
        // 第一步 先找到不满足非递减条件的点，如果这样的点超过两处，直接返回false
        int p = 0, cnt = 1;
        for (int i = 1; i < nums.size(); ++i)
        {
            if (nums[i] >= nums[i - 1])
                continue;
            if (cnt-- <= 0)
                return false;
            p = i - 1;
        }
        //第二步 判断
        if (cnt == 1 || p == 0 || p == nums.size() - 1 || nums[p - 1] <= nums[p + 1] || (p + 2 <= nums.size() && nums[p] <= nums[p + 2]))
            return true;
        return false;
    }
};